﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using SPPD.model;
using SPPD.controller;
using FluentNHibernate.Cfg;
using FluentNHibernate.Cfg.Db;
using NHibernate;
using NHibernate.Cfg;
using NHibernate.Tool.hbm2ddl;
using NHibernate.Linq;
using System.IO;
using System.Windows.Resources;
namespace SPPD
{
	/// <summary>
	/// Interaction logic for form_pengajuan.xaml
	/// </summary>
	public partial class form_pengajuan : Window
	{
		public form_pengajuan()
		{
			this.InitializeComponent();
			
			// Insert code required on object creation below this point.
		}

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            Window3 aju = new Window3();
            this.Hide(); aju.Show();
        }
        public void a()
        {
            ComboBox a = new ComboBox();
            controller_divisi con = new controller_divisi();
            List<divisi> div = con.load();
            for (int i = 0; i < div.Count; i++)
            {
                a.Items.Add(div[i].nama_divisi);
            }
            pegawai peg = new pegawai();
            peg.divisi = div[a.SelectedIndex];
        }

        private void button2_Click(object sender, RoutedEventArgs e)
        {
            pegawai dummy_pegawai= new pegawai();
            nhibernate nhi = new nhibernate();
            var factory = nhi.CreateSessionFactory();
            using (var session = factory.OpenSession())
            {
                var categories = session.Query<pegawai>()
                       .OrderBy(c => c.nama)
                       .ToList();

                for (int i = 0; i < categories.Count; i++)
                {
                    if (categories[i].nama == textBox1.Text)
                    {
                        dummy_pegawai = categories[i];
                        break;
                    }
                }
            }
            var dummy = new sppd
            {
                ketua = dummy_pegawai,
                tanggal_pengajuan = textBox3.Text,
                tanggal_perjalanan=textBox4.Text,
                tujuan=textBox5.Text,
                kepentingan=textBox6.Text,
                status=1
            };

            crud<sppd> n = new crud<sppd>();
            n.insert(dummy);
            MessageBox.Show("proposal sudah diupload");
        }

        private void button1_Click(object sender, RoutedEventArgs e)
        {
            Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog();
            dlg.FileName = "Document"; // Default file name
            dlg.DefaultExt = ".doc"; // Default file extension
            dlg.Filter = "Text documents (.doc)|*.doc"; // Filter files by extension

            // Show open file dialog box
            Nullable<bool> result = dlg.ShowDialog();

            // Process open file dialog box results
            if (result == true)
            {
                // Open document
                string filename = dlg.FileName;
                textBox8.Text = filename;
            }
            
        }

       
	}
}